package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.error.BusinessException;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/business/supplier")
@RestController
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    //查询物资的列表 分页带查询条件
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(@RequestParam Integer pageNum, @RequestParam Integer pageSize, SupplierVO supplierVO){
        PageVO<SupplierVO> supplierList = supplierService.findSupplierList(pageNum, pageSize, supplierVO);
        return ResponseBean.success(supplierList);
    }
    //添加物资来源信息
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        supplierService.add(supplierVO);
        return ResponseBean.success();
    }
    //编辑物资来源  回显数据
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        SupplierVO supplierVO = supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }
    //修改物资来源
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody SupplierVO supplierVO) throws BusinessException {
        supplierService.update(id,supplierVO);
        return ResponseBean.success();
    }
    //删除
    @GetMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);
        return ResponseBean.success();
    }
    //根据物资来源的id获取物资的信息
    @GetMapping("/getBySupplierId")
    public Supplier getBySupplierId(Long id){
        Supplier supplier = supplierService.getBySupplierId(id);
        return supplier;
    }
    //获取所有的物资信息来源
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<SupplierVO> supplierVOList = supplierService.findAll();
        return ResponseBean.success(supplierVOList);
    }
}
